package vip.xumy.admin.bmap.mapper;

import java.util.List;

import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import vip.xumy.admin.bmap.pojo.CityLocate;

/**
 * @author:mengyxu
 * @date:2021年10月25日
 */

@Mapper
public interface ICityLocateMapper {
	static final String BASE_COLUMN = "id, name, level, parent, max_lng, min_lng, max_lat, min_lat, count, space";

	@Insert({ "<script>", "INSERT INTO bmap_city_location ( ", BASE_COLUMN, " ) VALUES ",
			"<foreach collection='list' item='item' separator=','>",
			"(NULL, #{item.name}, #{item.level}, #{item.parent}, #{item.maxLng}, #{item.minLng}, #{item.maxLat}, #{item.minLat}, #{item.count}, #{item.space}) ",
			"</foreach>", "</script>" })
	void saveBatch(List<CityLocate> cityInfos);

	@Select({ "<script>", "SELECT ", BASE_COLUMN, " FROM bmap_city_location ", "<where>",
			"<if test='id != null'> AND id = #{id} </if>", "<if test='level != null'> AND level = #{level} </if>",
			"<if test='name != null'> AND name = #{name} </if>",
			"<if test='parent != null'> AND parent = #{parent} </if>",
			"<if test='partName != null'> AND name like CONCAT('%',#{partName},'%') </if>", "</where>", "</script>" })
	List<CityLocate> list(CityLocate example);

	@Update({ "UPDATE bmap_city_location SET max_lng = #{maxLng}, min_lng = #{minLng}, max_lat = #{maxLat}, ",
			"min_lat = #{minLat}, count = #{count}, space = #{space} WHERE id = #{id}" })
	void update(CityLocate cityInfo);

}
